package com.hwadee.ems.domain.vo;

import java.time.LocalDate;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import com.fasterxml.jackson.annotation.JsonIgnore;

import com.hwadee.ems.enums.Session;
import com.hwadee.ems.enums.DayOfWeek;
import com.hwadee.ems.enums.ApprovalStatus;
import com.hwadee.ems.service.IUserService;
import com.hwadee.ems.service.IApprovalService;
import com.hwadee.ems.service.ISemesterService;
import com.hwadee.ems.service.IClassroomService;
import com.hwadee.ems.service.impl.UserServiceImpl;
import com.hwadee.ems.service.impl.ApprovalServiceImpl;
import com.hwadee.ems.service.impl.SemesterServiceImpl;
import com.hwadee.ems.service.impl.ClassroomServiceImpl;
import com.hwadee.ems.domain.po.User;
import com.hwadee.ems.domain.po.Approval;
import com.hwadee.ems.domain.po.ClassroomApplication;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ClassroomApplicationVO {

    @JsonIgnore
    private IClassroomService classroomService = ClassroomServiceImpl.getInstance();

    @JsonIgnore
    private IUserService userService = UserServiceImpl.getInstance();

    @JsonIgnore
    private ISemesterService semesterService = SemesterServiceImpl.getInstance();

    @JsonIgnore
    private IApprovalService approvalService = ApprovalServiceImpl.getInstance();

    public ClassroomApplicationVO(ClassroomApplication classroomApplication) {
        this.id = classroomApplication.getId();
        this.classroomId = classroomApplication.getClassroomId();
        this.classroomName = classroomService.getById(this.classroomId).getName();
        this.applicantId = classroomApplication.getApplicantId();
        this.applicantName = userService.getById(this.applicantId).getName();
        this.semesterId = classroomApplication.getSemesterId();
        this.semester = semesterService.getById(this.semesterId).getName();
        this.approvalId = classroomApplication.getApprovalId();
        Approval approval = approvalService.getById(this.approvalId);
        this.approverId = approval.getApproverId();
        this.approverName = userService.getOptById(this.approverId)
            .map(User::getName)
            .orElse(null);
        this.approvalStatus = approval.getStatus();
        this.approvalOpinion = approval.getOpinion();
        this.approvalDate = approval.getApprovalDate();
        this.week = classroomApplication.getWeek();
        this.dayOfWeek = classroomApplication.getDayOfWeek();
        this.session = classroomApplication.getSession();
        this.reason = classroomApplication.getReason();
        this.applicationDate = classroomApplication.getApplicationDate();
    }

    private Long id;

    /**
     * 申请教室编号 references classroom(id) for (name)
     */
    private Long classroomId;

    /**
     * 申请教室名称
     */
    private String classroomName;

    /**
     * 申请人编号 references user(id) for (name)
     */
    private Long applicantId;

    /**
     * 申请人姓名
     */
    private String applicantName;

    /**
     * 申请学期编号 references semester(id) for (name)
     */
    private Long semesterId;

    /**
     * 申请学期
     */
    private String semester;

    /**
     * 审批编号 references approval(id) for (approver_id, approval_status, opinion, approval_date)
     */
    private Long approvalId;

    /**
     * 审批人编号 references user(id) for (name)
     */
    private Long approverId;

    /**
     * 审批人姓名
     */
    private String approverName;

    /**
     * 审批状态
     */
    private ApprovalStatus approvalStatus;

    /**
     * 审批意见
     */
    private String approvalOpinion;

    /**
     * 审批日期
     */
    private LocalDate approvalDate;

    /**
     * 申请周次
     */
    private Integer week;

    /**
     *  申请星期几，0代表星期日，1代表星期一，2代表星期二，3代表星期三，4代表星期四，5代表星期5，6代表星期6
     */
    private DayOfWeek dayOfWeek;

    /**
     * 申请节次，0代表1-2，1代表3-5，2代表6-7，3代表8-9，4代表10-12，5代表13-15
     */
    private Session session;

    /**
     * 申请原因
     */
    private String reason;

    /**
     * 申请填报日期
     */
    private LocalDate applicationDate;
    
}
